package com.manner.groupon.controller.user;

import com.manner.groupon.common.BaseResponse;
import com.manner.groupon.common.PageResult;
import com.manner.groupon.model.entity.User;
import com.manner.groupon.model.vo.LoginResultVo;
import com.manner.groupon.service.user.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Manner
 * @Description: 用户相关请求处理控制器
 * @DateTime: 2024/10/6 16:22
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    /**
     * @param code        登录手机号
     * @param invitePhone 邀请人手机号(可为空 '' )
     * @return BaseResponse<LoginResultVo < User>>
     * @description: 小程序前台用户登录
     * @author Manner
     * @date 2024/12/1 22:03
     */
    @GetMapping("/login/{code}/{inviteId}")
    public BaseResponse<LoginResultVo<User>> login(@PathVariable String code,
                                                   @PathVariable("inviteId") String invitePhone) {
        return userService.login(code, invitePhone);
    }

    @GetMapping("/admin")
    public BaseResponse<PageResult<User>> query(Integer current, Integer pageSize) {
        return userService.query_search(current, pageSize);
    }

}
